package com.flyu.myThread.Daemon;


// 测试守护线程
// 上帝守护你
public class TestDaemin {
    public static void main(String[] args) {
        God god = new God();
        You you = new You();

        Thread godThread = new Thread(god);
        // 设置God为守护线程
        godThread.setDaemon(true);  // 默认为false，即用户线程
        godThread.start();

        Thread youThread = new Thread(you);
        youThread.start();
    }
}

// 上帝 -- 守护线程
class God implements Runnable{

    @Override
    public void run() {
        while (true){
            System.out.println("上帝守护着你");
        }
    }
}

// 你 -- 用户线程
class You implements Runnable{

    @Override
    public void run() {
        for (int i = 1; i < 36500; i++) {
            System.out.println("你已经活了"+i+"天");
        }
        System.out.println("寿命已到，你离开了人世");
    }
}